package haonan3344.localbbs.util;

import java.io.*;

public class FileIO {
	
	public static String readFileToStr(String filename){
		File file = new File(filename);
        BufferedReader reader = null;
        StringBuffer sb = new StringBuffer();
        
        try {
			reader = new BufferedReader(new FileReader(file));
			String line=null;
			while ((line = reader.readLine()) != null) {
				sb.append(line+"\n");
            }
			reader.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
		return sb.toString();
	}
	
	public static boolean writeStrToFile(String filename, String content){
		
		boolean ret = false;
		
		File file = new File(filename);
        BufferedWriter writer = null;
        StringBuffer sb = new StringBuffer();
        
        try {
        	writer = new BufferedWriter(new FileWriter(file));
        	writer.write(content);
        	writer.flush();
        	writer.close();
        	ret=true;
        	
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
		return ret;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
